import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// 步骤1：装包
// 步骤2：导入这个 px 自动转为 vw/vh 的插件
import pxToVP from 'postcss-px-to-viewport-8-plugin'

// https://vite.dev/config/
export default defineConfig({
  plugins: [react()],
  server: {
    proxy: {
      '/api': {
        // 大家唯一需要做的事儿，是把 target 的值替换为老师的接口根路径
        target: 'https://api-ticket.liulongbin.top',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },
  // 步骤3
  css: {
    postcss: {
      plugins: [
        pxToVP({
          unitToConvert: 'px',
          // 把设计稿的尺寸，改成 375
          viewportWidth: 375,
          unitPrecision: 5,
          propList: ['*'],
          viewportUnit: 'vw',
          fontViewportUnit: 'vw',
          selectorBlackList: [],
          minPixelValue: 1,
          mediaQuery: false,
          replace: true,
          exclude: [],
          landscape: false,
          landscapeUnit: 'vw',
          landscapeWidth: 568
        })
      ]
    }
  }
})
